{Title: Basic Kontakt GUI Example}
{Author: Daniel Dehaan}
{Website: www.danielrdehaan.com}
{Notes: This script provides a basic example of a Kontakt instrument GUI}
{		that applies custom images to sliders and establishes a variable}
{		background image by vertically cropping and offseting a PNG 	}
{		that is taller than the height of script's performance view. 	}


{-----------------------------------------------------------}
{-----------------Initialization Callback-------------------}
{-----------------------------------------------------------}
on init
	{Make a performance view for this script.}
	make_perfview

	{Create variables for the performance view's deminensions.}
	{This is makes when you need to reference the instrument's GUI dimensions}
	{elsewhere within the script.}
	declare $perf_view_height := 302
	declare $perf_view_width := 633

	{Create a variable with the instrument's header height.}
	declare $instrument_header_height := 70
	
	{Set the performance view's dimensions.}
	set_ui_height_px($perf_view_height)
	set_ui_width_px($perf_view_width)
	
	{Set the wallpaper to a custom PNG stored in '/Resources/Pictures' folder.}
	set_control_par_str($INST_WALLPAPER_ID,$CONTROL_PAR_PICTURE,"Background-Image")
	
	{Sets the Instrument's Icon PNG stored in '/Resources/Pictures' folder.}
	set_control_par_str($INST_ICON_ID,$CONTROL_PAR_PICTURE,"Instrument-Icon")
	
	{Declare the GUI controls.}
	declare ui_value_edit $contrast (1,10,1)
	declare ui_slider $slider1 (0,1000000)
	declare ui_slider $slider2 (0,1000000)

	{Set GUI controls initial values.}
	$contrast := 10
	$slider1 := 0
	$slider2 := 0
	
	{Store the id of GUI controls in a variable.}
	declare $contrast_value_edit_id := get_ui_id($contrast)
	declare $slider1_id := get_ui_id($slider1)
	declare $slider2_id := get_ui_id($slider2)

	{Make it so the slider's values are stored when the instrument is saved.}
	make_persistent($contrast)
	make_persistent($slider1)
	make_persistent($slider2)

	{Make is to the slider's values are recalled with the instrument is loaded.}
	read_persistent_var($contrast)
	read_persistent_var($slider1)
	read_persistent_var($slider2)

	{Adjust the offset of the wallpaper image.}
	set_skin_offset(($contrast - 1) * ($perf_view_height - 2 + $instrument_header_height))

	{Set the GUI controls to use a custom PNG stored in '/Resources/Pictures' folder.}
	set_control_par_str($slider1_id, $CONTROL_PAR_PICTURE, "Knob-10")
	set_control_par_str($slider2_id, $CONTROL_PAR_PICTURE, "Knob-10")

	{Set the displayed text of the contrast GUI control to nothing.}
	set_text($contrast, "")
	
	{Hide the contrast GUI control's background.}
	set_control_par(get_ui_id($contrast), $CONTROL_PAR_HIDE, $HIDE_PART_BG)

	{Set the GUI control's mouse behaviour.}
	set_control_par($slider1_id, $CONTROL_PAR_MOUSE_BEHAVIOUR, -2000)
	set_control_par($slider2_id, $CONTROL_PAR_MOUSE_BEHAVIOUR, -2000)

	{Position the GUI controls.}
	move_control_px($contrast, 0, $perf_view_height - 18)
	move_control_px($slider1, 510, 225)
	move_control_px($slider2, 580, 225)
end on


{-----------------------------------------------------------}
{---------------Adjust Contrast Callback--------------------}
{-----------------------------------------------------------}
on ui_control ($contrast)
	{Adjust the offset of the wallpaper image.}
	set_skin_offset(($contrast - 1) * ($perf_view_height - 2 + $instrument_header_height))
	
	{Change the custom PNG file used for the two sliders based upon $contrast's current value.}
	select ($contrast)
		case 1
			set_control_par_str($slider1_id, $CONTROL_PAR_PICTURE, "Knob-01")
			set_control_par_str($slider2_id, $CONTROL_PAR_PICTURE, "Knob-01")
		case 2
			set_control_par_str($slider1_id, $CONTROL_PAR_PICTURE, "Knob-02")
			set_control_par_str($slider2_id, $CONTROL_PAR_PICTURE, "Knob-02")
		case 3
			set_control_par_str($slider1_id, $CONTROL_PAR_PICTURE, "Knob-03")
			set_control_par_str($slider2_id, $CONTROL_PAR_PICTURE, "Knob-03")
		case 4
			set_control_par_str($slider1_id, $CONTROL_PAR_PICTURE, "Knob-04")
			set_control_par_str($slider2_id, $CONTROL_PAR_PICTURE, "Knob-04")
		case 5
			set_control_par_str($slider1_id, $CONTROL_PAR_PICTURE, "Knob-05")
			set_control_par_str($slider2_id, $CONTROL_PAR_PICTURE, "Knob-05")
		case 6
			set_control_par_str($slider1_id, $CONTROL_PAR_PICTURE, "Knob-06")
			set_control_par_str($slider2_id, $CONTROL_PAR_PICTURE, "Knob-06")
		case 7
			set_control_par_str($slider1_id, $CONTROL_PAR_PICTURE, "Knob-07")
			set_control_par_str($slider2_id, $CONTROL_PAR_PICTURE, "Knob-07")
		case 8
			set_control_par_str($slider1_id, $CONTROL_PAR_PICTURE, "Knob-08")
			set_control_par_str($slider2_id, $CONTROL_PAR_PICTURE, "Knob-08")
		case 9
			set_control_par_str($slider1_id, $CONTROL_PAR_PICTURE, "Knob-09")
			set_control_par_str($slider2_id, $CONTROL_PAR_PICTURE, "Knob-09")
		case 10
			set_control_par_str($slider1_id, $CONTROL_PAR_PICTURE, "Knob-10")
			set_control_par_str($slider2_id, $CONTROL_PAR_PICTURE, "Knob-10")
	end select
end on
